<?php
class Shop_View_Helper_FindMainImage extends Zend_View_Helper_Abstract {
	
	/**
	 * @param array $images
	 * @param array|integer $row
	 * @return array
	 */
	public function findMainImage(array $images, $row, $key = null) {
		$id = is_array($row) ? $row['id'] : $row;
		$image = array();
		foreach ($images as $image) {
			if ($image['id'] == $id) {
				return $image;
			}
		}

		return (null === $key) 
			? $image : @$image[$key];
	}
}